import requests
from concurrent.futures import ThreadPoolExecutor

# 接口 URL 模板
url_template = "http://106.53.146.53:7001/api/ccSmart/checkTopicByTrackSpanId/invoke?spanId={}"

# 不同的 spanId 列表
span_ids = [
"xe6e1tdvtdzwg",
"xee0swsszn5s0",
"xehajy9kmu2v4",
"xeg5text7qz9c",
"xegave6kbk1kw",
"xea22ohc71pts",
"xegspo869b20w",
"xeein6u6y6fwg",
"xef0hgvpmld6o",
"xehe4eob3v668",
"xeluox1ausetc",
"xel7snr6me8e8",
"xecshx2ld3y0w",
"xecxjwbbkeqyo",
"xeea0r6mt0etc",
"xeia8icfybrwg",
"xecld094hjnr4",
"xel5pq6jyyv40",
"xeifvwbo2zjls",
"xecqezi37zz7k",
"xecw2dh1fk9hc",



]

# 请求头
headers = {
    'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
}

# 定义请求函数
def call_api(span_id):
    url = url_template.format(span_id)
    try:
        requests.get(url, headers=headers, timeout=1)  # 设置 timeout 避免阻塞
        print(f"Request sent with spanId={span_id}")
    except Exception as e:
        print(f"Error with spanId={span_id}: {e}")

# 使用线程池异步调用
with ThreadPoolExecutor(max_workers=10) as executor:  # 最多 10 个并发
    executor.map(call_api, span_ids)

print("All requests sent asynchronously!")